package com.example.demo2.exception;

import com.example.demo2.enums.ResponseCode;
import lombok.Data;

/**
 * @ClassName: BusinessException
 * @author thomas
 */
@Data
public class BusinessException extends RuntimeException {

  private static final long serialVersionUID = 1L;

  private String code;

  private Object data;

  public BusinessException(String message) {
    super(message);
  }

  public BusinessException(String code, String message) {
    super(message);
    this.code = code;
  }

  public BusinessException(String code, Object data, String message) {
    super(message);
    this.code = code;
    this.data = data;
  }

  public BusinessException(ResponseCode responseCode) {
    super(responseCode.getMessage());
    this.code = responseCode.getCode();
  }

  public BusinessException(ResponseCode responseCode, String message) {
    super(message);
    this.code = responseCode.getCode();
  }

  // 不写入 stack trace 以提高性能
  @Override
  public synchronized Throwable fillInStackTrace() {
    return this;
  }
}
